Repository navigation
fix: let self-parsing types bind as a last resort - #197
Merged
mromaszewicz merged 1 commit intoNov 23, 2026
Merged
mromaszewicz merged 1 commit into
mromaszewicz merged 1 commit into
Conversation
BindStringToObject only found a type's own parsing logic in two narrow cases: Binder on the destination exactly as passed, and encoding.TextUnmarshaler on array kinds. An optional field hands it a **T, on which neither interface is visible, and a TextUnmarshaler slice or struct such as net.IP, netip.Addr or big.Int was never consulted, so all of these failed with "can not bind to destination of type". Where no built-in conversion applies, check the dereferenced destination for Binder and then encoding.TextUnmarshaler before giving up. The array case uses the same check, which also fixes an optional *uuid.UUID property of an exploded form object. This is a fallback only. Every destination which binds today takes the same path as before, including time.Time and types.Date, whose lenient parsing stays ahead of their stricter UnmarshalText, and base64 decoding for format: byte. A Binder on a primitive kind behind an optional pointer is still parsed as a plain primitive without calling Bind. Honoring Bind there changes the result of requests which bind today, so it is a separate change. Part of oapi-codegen#196 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #196 (1 of 2).
Problem
BindStringToObjectonly found a type's own parsing logic in two narrow cases:Binderon the destination exactly as passed, andencoding.TextUnmarshaleron array kinds (theuuid.UUIDcase). Everything else with no built-in conversion failed withcan not bind to destination of type: slice/struct:Binderslice, struct or map behind the pointer of an optional field, where the destination is a**Tand the interface is not visible;TextUnmarshalerslice or struct, with or without a pointer, such asnet.IP,netip.Addrorbig.Int;*uuid.UUIDproperty of an exploded form object, for the same**Treason.Fix
Where no built-in conversion applies, check the dereferenced destination for
Binder, thenencoding.TextUnmarshaler, before giving up. The array case uses the same check.Compatibility
Additive only. The new check runs solely on paths that previously returned an error, so every destination that binds today takes the same path as before. In particular:
time.Timeandtypes.Datekeep their lenient parsing ahead of their stricterUnmarshalText;format: bytestill base64-decodes first, even into aTextUnmarshalersuch asnet.IP;TestBindStringToObject_SelfParsingIsLastResortpins these.Not in this PR
A
Binderon a primitive kind behind an optional pointer is still parsed as a plain primitive without callingBind. Fixing that changes the result of requests that bind today, so it is in a separate PR. The two are independent and merge cleanly in either order.🤖 Generated with Claude Code